<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/6
 * Time: 15:27
 */

namespace app\modules\api\service;


use app\modules\api\models\Leaders;
use app\modules\api\models\Quote;
use app\modules\api\models\QuoteType;
use app\modules\api\models\Suppliers;

class SellService
{

    public function quoteList($p, $s, $where)
    {
        $model = new Quote();
        return $model->list($p, $s, $where);
    }

    public function quoteSize($where)
    {
        $model = new Quote();
        return $model->size($where);
    }

    /**大客户组联系人
     * @return array
     */
    public function leader()
    {
        $model = new Leaders();
        $list = $model->list();
        return $list;
    }

    /**添加一条对方负责人记录
     * @param $data
     * @return int
     */
    public function addLeader($data)
    {
        $model = new Leaders();
        return $model->add($data);
    }

    public function getSupplier()
    {
        $model = new Suppliers();
        $list = $model->list();
        foreach ($list as $k => $v) {
            $list[$k]['key'] = $v['id'];
            $list[$k]['label'] = $v['company_name'] . $v['name'];
        }
        return $list;
    }

    public function addSupplier($data)
    {
        $model = new Suppliers();
        return $model->add($data);
    }

    public function addQuote($data)
    {
        $model = new Quote();
        return $model->add($data);
    }

    /**通过id获取大客户组报价
     * @param $id
     * @return array|bool
     */
    public function getQuoteById($id)
    {
        if (is_numeric($id)) {
            $model = new Quote();
            return $model->getQuoteById($id);
        }
    }

    public function delQuote($id)
    {
        $model = new Quote();
        return $model->del($id);
    }

    public function getQuoteType()
    {
        $model = new QuoteType();
        return $model->list();
    }
}